package com.hs.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.hs.sfzy.entity.ConsultLevel;
import com.hs.sfzy.entity.Specialty;
import com.hs.sfzy.service.ConsultLeverService;
import com.hs.sfzy.service.ConsultService;
import com.hs.sfzy.service.SpecialtyService;
import com.hs.sfzy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName SpecialtyController
 * @Description TODO
 * @Author 李明辉
 * @Date 2024年10月24日 17:20
 * @Version 1.0
 */
@RestController
@RequestMapping("/consultlever")
public class ConsultLeverController {
    @Autowired
    private ConsultLeverService consultLeverService;

    @GetMapping
    public Result selectAll(@RequestBody ConsultLevel consultLevel){
        List<ConsultLevel> consultLevels = consultLeverService.selectAll(consultLevel);
        return Result.success(consultLevels);
    }

    @GetMapping("/findByPage")
    public Result selectByPage(
            @RequestParam(required = false,defaultValue = "1") int pageNum,
            @RequestParam(required = false,defaultValue = "5") int pageSize,
            ConsultLevel consultLevel){
        PageInfo<ConsultLevel> consultLevelPageInfo = consultLeverService.selectByPageInfo(pageNum, pageSize, consultLevel);
        return Result.success(consultLevelPageInfo);
    }

    @PostMapping()
    public Result insert(@RequestBody  ConsultLevel consultLevel){
        int num = consultLeverService.insert(consultLevel);
        if (num != 0){
            return Result.success("添加成功");
        }else {
            return Result.error("添加失败");
        }
    }

    @PutMapping()
    public Result update(@RequestBody  ConsultLevel consultLevel){
        int num = consultLeverService.update(consultLevel);
        if (num != 0){
            return Result.success("修改成功");
        }else {
            return Result.error("修改失败");
        }
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Long id){
        int num = consultLeverService.delete(id);
        if (num != 0){
            return Result.success("删除成功");
        }else {
            return Result.error("删除失败");
        }
    }

    @GetMapping("/getInfo")
    public Result<List<ConsultLevel>> getInfo(){
        List<ConsultLevel> grades = consultLeverService.getInfo();
        return Result.success(grades);
    }

    @GetMapping("/getName")
    public Result<List<String>> getName(){
        List<String> grades = consultLeverService.getName();
        return Result.success(grades);
    }
}
